<?php

namespace app\rongcui\validate;

use think\Validate;

class RongcuiAgencyUserValidate extends Validate
{
    protected $rule = [
        'name' => 'require',
        'phone' => 'requireNotWith:tel',
        'tel' => 'requireNotWith:phone',
    ];

    protected $message = [
        'name.require' => '姓名不能为空',
        'phone.requireNotWith' => '手机号电话不能同时为空',
        'tel.requireNotWith' => '手机号电话不能同时为空',
    ];

    // 自定义验证规则
    protected function requireNotWith($value,$rule,$data)
    {
        $val = $this->getDataValue($data, $rule);
        if (empty($val)) {
            return !empty($value) || '0' == $value;
        } else {
            return true;
        }
    }
}